﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CRM_WF.GestionEleveservice;
using CRM_WF.GestionAgenceService;
using CRM_WF.GestionCentreFormationService;
using CRM_WF.GestionCircuitService;
using CRM_WF.GestionEmployeService;
using CRM_WF.GestionFormateurService;
using CRM_WF.GestionFormationService;
using CRM_WF.GestionNotesService;
using CRM_WF.GestionPermisService;
using CRM_WF.GestionSessionConduiteService;
using CRM_WF.GestionSessionFormationService;
using CRM_WF.GestionThemeService;
using CRM_WF.GestionTypeSessionService;
using CRM_WF.GestionVehiculeService;
using System.ServiceModel;


namespace CRM_WF
{
    class WebServices
    {
        GestionEleveServiceClient gestionEleve;
        GestionAgenceServiceClient gestionAgence;
        GestionCentreFormationServiceClient  gestionCentreFormation;
        GestionCircuitServiceClient gestionCircuit;
        GestionEmployeServiceClient gestionEmploye;
        GestionFormateurServiceClient gestionFormateur;
        GestionFormationServiceClient gestionFormation;
        GestionNotesServiceClient gestionNote;
        GestionPermisServiceClient gestionPermis;
        GestionSessionConduiteServiceClient gestionSessionConduite;
        GestionSessionFormationServiceClient gestionSessionFormation;
        GestionThemeServiceClient gestionTheme;
        GestionTypeSessionServiceClient gestionTypeSession;
        GestionVehiculeServiceClient gestionVehicule;

        public WebServices()
        {
            try
            {
                gestionEleve = new GestionEleveServiceClient("WSHttpBinding_IGestionEleveService");
                gestionAgence = new GestionAgenceServiceClient("WSHttpBinding_IGestionAgenceService");
                gestionCentreFormation = new GestionCentreFormationServiceClient("WSHttpBinding_IGestionCentreFormationService");
                gestionCircuit = new GestionCircuitServiceClient("WSHttpBinding_IGestionCircuitService");
                gestionEmploye = new GestionEmployeServiceClient("WSHttpBinding_IGestionEmployeService");
                gestionFormateur = new GestionFormateurServiceClient("WSHttpBinding_IGestionFormateurService");
                gestionFormation = new GestionFormationServiceClient("WSHttpBinding_IGestionFormationService");
                gestionNote = new GestionNotesServiceClient("WSHttpBinding_IGestionNotesService");
                gestionPermis = new GestionPermisServiceClient("WSHttpBinding_IGestionPermisService");
                gestionSessionConduite = new GestionSessionConduiteServiceClient("WSHttpBinding_IGestionSessionConduiteService");
                gestionSessionFormation = new GestionSessionFormationServiceClient("WSHttpBinding_IGestionSessionFormationService");
                gestionTheme = new GestionThemeServiceClient("WSHttpBinding_IGestionThemeService");
                gestionTypeSession = new GestionTypeSessionServiceClient("WSHttpBinding_IGestionTypeSessionService");
                gestionVehicule = new GestionVehiculeServiceClient("WSHttpBinding_IGestionVehiculeService");
            }
            catch(Exception e)
            {
                throw new Exception("Erreur création web service. Vérifiez que les services ASP.net soit lancé. " + e.Message);
            }
        }

        public List<string> RecupererToutLesEleves()
        {
            List<string> retourListEleves = new List<string>();
            foreach (Eleve eleve in gestionEleve.GetAllEleves())
            {
                retourListEleves.Add(eleve.Nom + " " + eleve.Prenom);
            }
            return retourListEleves;
        }

        public List<string> ListeEleveDeLaJournee(DateTime date)
        {
            List<string> retourListEleves = new List<string>();
            foreach (SessionConduite sessionDeConduite in gestionSessionConduite.GetSessionConduiteByDay(date))
            {
                Eleve eleve = gestionEleve.GetEleveById(sessionDeConduite.EleveID); // A MODIF !
               retourListEleves.Add(eleve.Nom + " " + eleve.Prenom);
            }
            return retourListEleves;
        }

        public void ajoutSessionFormation(/*da*/)
        {
            SessionFormation session = new SessionFormation();
            //session.DateDebut

        }

        public List<string> recupererTypesPermis()
        {

            List<string> listePermis = new List<string>();
            foreach (Permis permis in gestionPermis.GetAllPermis())
            {
                listePermis.Add(permis.Description);
            }
            return listePermis;
        }
         
        public List<string> bob()
        {
            string toto = "";
            if (toto.GetType() == typeof(string))
            {
                return new List<string>();
            }
             return new List<string>();
        }

        public void NoterEleve(int note, int eleveID)
        {
            eleveID = 1;
            Notes addNote = new Notes()
            {
                Note=note ,
                EleveID = eleveID,

            };
            gestionNote.CreateNote(addNote);
        }
        public List<string> RecupererListeFormationsFormateur()
        {
            List<string> Retourformation = new List<string>();
            foreach (SessionFormation session in gestionSessionFormation.GetAllSessionFormations ())
            {
                Retourformation.Add(session.TypeSessionID + ","+session.DateDebut +","+ gestionFormateur.GetFormateurById (session.FormateurID).Nom  +" "
                    + gestionFormateur.GetFormateurById (session.FormateurID).Prenom +","+session.DateFin + ", Formateur");
            }
            return Retourformation;
        }

    }
}
